import Vue from "vue";
import Vuex from "vuex";
//导入用户模块数据
import userStore from './modules/user'
import collapse from './modules/collapse'
import showSotre from './modules/show'
import VuePersistedStatePlugin from 'vuex-persistedstate';
Vue.use(Vuex);

const store = new Vuex.Store({
  state:{
    //根数据，直接使用this.$store.state.count访问
    count:0,
  },
  modules:{
    //使用用户模块数据
    //模块数据使用this.$store.state.模版名.数据key访问
    //列如：this.$store.userStore.nickname
    userStore,
    collapse,
    showSotre
  },
  plugins:[
    VuePersistedStatePlugin({
      //将数据持久化到localStorage本地存储
      storage:window.localStorage,
      reducer(data){
        return{
          userStore:data.userStore,
          collapse:data.collapse,
          showSotre:data.showSotre
        }
      }
    })
  ]
});

export default store;